<template>
  <div class="app-container">

    <div class="search-container">
      <div class="search-title">
        查询条件
      </div>
      <div class="search-form">
        <div class="form-row">
          <div class="form-column">
            <span class="column-title">课目名称</span>
            <el-input v-model="queryParams.projectName" placeholder="请输入" class="input-w150" clearable
              @keyup.enter.native="handleQuery" />
          </div>
          <div class="form-column">
            <span class="column-title">创建时间</span>
            <el-date-picker v-model="dateRange" class="input-w383" value-format="yyyy-MM-dd" type="daterange"
              range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" clearable></el-date-picker>
          </div>
          <div class="form-column">
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </div>
        </div>
      </div>
    </div>


    <div class="body-container">
      <div class="operation-bar">
        <div class="bar-title">
          培训课目列表
        </div>
      </div>

      <el-table v-loading="loading" stripe :data="dataList">
        <el-table-column type="index" label="#" align="center" min-width="100"></el-table-column>
        <el-table-column label="课目名称" prop="projectName" align="center" min-width="200" />
        <el-table-column label="年份" prop="roleId" align="center" min-width="120">
          <template slot-scope="scope">
            {{ parseTime(scope.row.createStamp, '{y}') }}
          </template>
        </el-table-column>
        <el-table-column label="教员" prop="subjectTeacherList" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.subjectTeacherList ? scope.row.subjectTeacherList.join('、') : '' }}
          </template>
        </el-table-column>
        <el-table-column label="起止时间" align="center" min-width="200">
          <template slot-scope="scope">
            <template v-if="scope.row.startTime && scope.row.endTime">
              {{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }} ~ {{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}
            </template>
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="end" align="center">
          <template slot-scope="scope">
            <el-tag size="mini" type="danger" v-if="scope.row.end">已结束</el-tag>
            <el-tag size="mini" type="success" v-if="!scope.row.end">进行中</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="简介" prop="projectDesc" align="center" min-width="200" show-overflow-tooltip />
        <el-table-column label="创建时间" prop="roleId" align="center" min-width="170">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createStamp) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" min-width="120" class-name="small-padding fixed-width">
          <div class="table-option" slot-scope="scope" v-if="scope.row.roleId !== 1">
            <span @click="handlePersonManage(scope.row)">查询成绩</span>
          </div>
        </el-table-column>
      </el-table>

      <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

  </div>
</template>
  
<script>
import { findProjectList, delProjectById , findMyProjectList } from "@/api/subject";

export default {
  name: "file",
  dicts: [],
  components: {
  },
  data () {
    return {
      editType: 'add',
      editData: {},
      total: 0,
      editTitle: "",
      editDialog: false,
      dataList: [],
      loading: true,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: '',
        userId: this.$store.state.user.id
      },
      dateRange: [],
    };
  },
  created () {
    console.log(this.$store.state.user.id)
    this.getList();
  },
  methods: {
    // 学员管理
    handlePersonManage (row) {
      this.$router.push({
        path: 'search_personList',
        query: {
          projectId: row.id,
          projectName: row.projectName
        }
      })
    },
    // 查询
    async getList () {
      this.loading = true;
      console.log(this.$store.state.user.userInfo.personnelId)
      this.queryParams.userId= this.$store.state.user.userInfo.personnelId
      this.queryParams.personnelId = this.$store.state.user.userInfo.personnelId
      const res = await findMyProjectList(this.addStartDateRange(this.queryParams, this.dateRange))
      this.loading = false;
      if (res.code === 200) {
        this.dataList = res.rows || [];
        this.total = res.total || 0;
      } else {
        this.dataList = [];
        this.total = 0;
      }
    },
    // 查询
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    resetQuery () {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        projectName: '',
        userId: this.$store.state.user.id
      }
      this.dateRange = []
      this.handleQuery();
    }
  }
};
</script>